package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author hzy
 * @since 2023-09-09
 */
@RestController
@RequestMapping("/questions")
@Api(tags = "问题相关接口")
@Slf4j
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService questionService;

    /**
     * 新增互动问题(用户端)
     *
     * @param questionFormDTO
     */
    @ApiOperation("新增互动问题(用户端)")
    @PostMapping
    public void addInteractionQuestions(@RequestBody QuestionFormDTO questionFormDTO) {
        log.info("调用>>>新增互动问题(用户端)");
        questionService.addInteractionQuestions(questionFormDTO);
    }

    /**
     * 分页查询问题(用户端)
     *
     * @param query
     * @return
     */
    @ApiOperation("分页查询问题(用户端)")
    @GetMapping("/page")
    public PageDTO<QuestionVO> selectPage(@Validated QuestionPageQuery query) {
        log.info("调用>>>分页查询问题(用户端)");
        return questionService.selectPage(query);
    }

    /**
     * 根据id查询问题详情(用户端)
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id查询问题详情(用户端)")
    @GetMapping("/{id}")
    public QuestionVO selectDescriptionById(@PathVariable("id") Long id) {
        log.info("调用>>>根据id查询问题详情(用户端)");
        return questionService.selectDescriptionById(id);
    }

    /**
     * 修改互动问题(用户端)
     *
     * @param id
     * @param dto
     */
    @PutMapping("/{id}")
    @ApiOperation("修改互动问题(用户端)")
    public void updateQuestion(@PathVariable("id") Long id, @RequestBody QuestionFormDTO dto) {
        questionService.updateQuestion(id, dto);
    }
}
